//
//  BaseViewController.m
//  parent
//
//  Created by 闫珍 on 15/8/7.
//  Copyright (c) 2015年 ci123. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
    {
        [self setEdgesForExtendedLayout:UIRectEdgeNone];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - MBHud

- (void)showHud:(NSString *)title isDim:(BOOL)isDim {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    _hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
    _hud.dimBackground = isDim;
    if(title.length > 0) {
        _hud.labelText = title;
    }
}

- (void)showHudComplete:(NSString *)title success:(BOOL)success {
    NSString *name = success ? @"success" : @"excla";
    _hud.dimBackground = NO;
    _hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:name]];
    _hud.mode = MBProgressHUDModeCustomView;
    if(title.length > 0) {
        _hud.labelText = title;
    }
    [_hud hide:YES afterDelay:1];
}

- (void)ShowExclaHud:(NSString *)title{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    _hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
    [self showHudComplete:title success:NO];
}

- (void)ShowExclaHud2:(NSString *)title{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    _hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
    [self showHudComplete:title success:YES];
}

- (void)hideHud2 {
    [_hud hide:YES];
}

-(void)CustomBackButton
{
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                                                                    target:nil action:nil];
    negativeSpacer.width = -10;
    
    UIButton *backButton = [[UIButton alloc] initWithFrame: CGRectMake(0, 0, 40.0f, 44.0f)];
    UIImage *backImage = [[UIImage imageNamed:@"左箭头"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [backButton setImage:backImage  forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(popBack) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects: negativeSpacer, backButtonItem, nil];
}
- (UIButton *)createNavRightButton:(NSString *)showName target:(id)target action:(SEL)action
{
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
    float fontsize=18.0f;
    if(showName.length>2){
        fontsize=16.0f;
    }
    
    button.titleLabel.font = [UIFont systemFontOfSize:fontsize];
    [button setTitleColor:UIColorMake(100, 100, 100) forState:UIControlStateNormal];
    [button setTitle:showName forState:UIControlStateNormal];
    button.showsTouchWhenHighlighted = YES;
    [button setBackgroundColor:[UIColor clearColor]];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    return button;
}

-(void)popBack
{
    [self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
